package movee.jpa.multi.source.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 *
 *
 * @author movee
 */
@Getter
@AllArgsConstructor
public enum OperationStatus {

    WAIT_COMMIT(0, "待提交", ""),
    WAIT_VERIFY1(1, "待一审", ""),
    WAIT_VERIFY2(2, "待二审", ""),
    WAIT_VERIFY3(3, "待三审", ""),
    WAIT_OPERATE(4, "待操作", ""),
    EXECUTING(5, "操作中", ""),
    FINISH_SUCCESS(6, "已结单-成功", ""),
    FINISH_FAILED(7, "已结单-失败", ""),
    FINISH_CANCEL(8, "已结单-取消", ""),
    FINISH_TIMEOUT(9, "已结单-超时", "");

    private final int id;
    private final String chineseName;
    private final String description;

    private static final Map<String, OperationStatus> CHINESE_MAP = new HashMap<>();
    private static final Map<String, OperationStatus> NAME_MAP = new HashMap<>();
    private static final Map<String, OperationStatus> ID_MAP = new HashMap<>();

    static {
        for (OperationStatus status : OperationStatus.values()) {
            CHINESE_MAP.put(status.getChineseName().toLowerCase(), status);
            NAME_MAP.put(status.name().toLowerCase(), status);
            ID_MAP.put(String.valueOf(status.id), status);
        }
    }

    public static OperationStatus fromChineseName(String chineseName) {
        return chineseName == null ? null : CHINESE_MAP.get(chineseName.toLowerCase());
    }

    public static OperationStatus fromName(String name) {
        return name == null ? null : NAME_MAP.get(name.toLowerCase());
    }

    public static OperationStatus fromId(String id) {
        return id == null ? null : ID_MAP.get(id);
    }
}
